package com.yyy.tcc.service.compensation;

import java.util.concurrent.atomic.AtomicStampedReference;

public class JoinExplainDemo {
    public static void main(String[] args) throws InterruptedException {
        // main线程创建并启动threadA
        Thread threadA = new Thread(() -> {
            try {
                System.out.println("ThreadA: 我开始执行，睡眠2秒");
                Thread.sleep(2000);
                System.out.println("ThreadA: 我执行完了");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        System.out.println("Main线程: 启动ThreadA");
        threadA.start();

        System.out.println("Main线程: 调用threadA.join()，我要等待ThreadA完成");
        threadA.join();  // main线程在这里等待threadA完成

        System.out.println("Main线程: ThreadA完成了，我继续执行");

    }
}
